package com.xieyingwangluo.yxpart.api;

import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.entity.DemoModel;
import com.xieyingwangluo.yxpart.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Api(tags = "不能使用,编写中.....demo接口")
@Controller
@RequestMapping(value = "/api/v1/demo")
public class DemoBaseRest extends BaseRest {

    @Autowired
    private DemoService demoService;

    @ApiOperation(value = "获取数据测试接口", notes = "Get Rest接口的Demo方法", produces = "application/json")
    @ApiImplicitParam(name = "id", value = "demo_Id", required = true, dataType = "String", paramType = "query", defaultValue = "1234555SHA")
    @ResponseBody
    @GetMapping(value = "/selO")
    public Result selO_demo(@RequestHeader(name = "token", defaultValue = "token") String token,
                            @RequestParam("id") String id) {
        logger.info("获取demo信息 start....");
        return demoService.selById(id);
    }

    @ApiOperation(value = "新增demo", notes = "post Rest接口的Demo方法", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "主键", required = false, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "user_code", value = "账号", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "pwd", value = "密码", required = true, dataType = "String", paramType = "form")
    })
    @ResponseBody
    @PostMapping(value = "/add")
    public Result add_demo(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                           DemoModel demoModel) {
        logger.info("获取用户信息 start....");
        //如果demoModel為空
        //logger.error("demoModel is null =>"+(demoModel==null));
        return demoService.add(demoModel);
    }

    @ApiOperation(value = "查询所有", produces = "application/json")
    @ResponseBody
    @RequestMapping(value = "/selA", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
    public Result selA() {

        return demoService.selA();
    }


}
